<template>
    <view class="chargemoney">
        <view class="minela">
            <image class="leftimge" src="../../static/img/tethe.png"></image>
            <text>USDT</text>
        </view>
        <view class="typelian">
            <view class="linclas">链类型：</view>
            <view class="vallian">
                {{gol}}
            </view>
        </view>
        <view class="modulqr">
            <view class="tbj">
                <image class="qrcode" :src="qrimg"></image>
            </view>
            <view class="tbj">
                <view class="keepqr" @click="down">保存二维码</view>
            </view>
            <view class="tbj">
                <view class="chongqr">充币地址</view>
            </view>
            <view class="tbj">
                <view class="qradds">{{addRess}}</view>
            </view>
            <view class="tbj">
                <view class="dgpqr" @click="copy">复制地址</view>
            </view>
            <view class="tbj">
                <view class="linehang"></view>
            </view>
            <view class="tottl">
                禁止向上述地址充值任何非{{gol}}资产，否则资产将不可找回
            </view>
        </view>
    </view>
</template>

<script>
    let uinfo;
    import request from "../../untils/request.js";
    import qr from "../../static/wxqrcode.js";
    export default {
        data() {
            return {
                addRess: '',
                gol: '',
                qrimg: '',
            }
        },
        onLoad() {
            uinfo = uni.getStorageSync('userInfo');
            this.pagmg();
        },
        methods: {
            pagmg() {
                request.postAssets('/assets/userWalletInfo/queryUserWalletInfo', {
                    userId: uinfo.userId,
                }).then(res => {
                    if (res.code == '200') {
                        this.addRess = res.data.items[0].address;
                        this.gol = res.data.items[0].chainName;

                        let img = qr.createQrCodeImg(res.data.items[0].address, {
                            size: parseInt(300)
                        })
                        this.qrimg = img;
                    }
                })
            },
            //一键复制
            copy() {
                // #ifdef H5
                this.$copyText(this.addRess).then(
                    res => {
                        uni.showToast({
                            title: '复制成功'
                        })
                    }
                )
                // #endif
                // #ifndef H5
                uni.setClipboardData({
                    data: this.addRess,
                    success: () => {
                        uni.showToast({
                            title: '复制成功'
                        })
                    }
                })
                // #endif

            },
            //保存图片
            down() {
                console.log('2')
                uni.downloadFile({ //下载
                    url: this.qrimg, //图片下载地址
                    success: res => {
                        if (res.statusCode === 200) {
                            uni.saveImageToPhotosAlbum({ //保存图片到系统相册。
                                filePath: res.tempFilePath, //图片文件路径
                                success: function() {
                                    uni.showToast({
                                        title: '图片保存成功',
                                        icon: 'none',
                                    });
                                },
                                fail: function(e) {
                                    console.log(e);
                                    uni.showToast({
                                        title: '图片保存失败',
                                        icon: 'none',
                                    });
                                }
                            });
                        }
                    }
                });
            },
        }
    }
</script>

<style>
    .chargemoney {
        padding: 20px 0 50px 0;
        background-color: #F5F5F5;
    }

    .minela {
        width: 680rpx;
        height: 108rpx;
        padding: 0 0 0 20px;
        background: #FFFFFF;
        margin: 0 auto 20rpx;
        border-radius: 6px;
        display: flex;
        align-items: center;
    }

    .minela .leftimge {
        width: 60rpx;
        height: 60rpx;
        margin: 0 10rpx 0 0;
    }

    .minela text {
        font-size: 16px;
        font-family: Source Han Sans CN;
        font-weight: 500;
        color: #333333;
    }

    .typelian {
        margin: 0 0 0 10px;
    }

    .typelian .linclas {
        font-size: 16px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 27px;
        color: #333333;
        margin: 0 0 20px 0;
    }

    .typelian .vallian {
        width: 81px;
        height: 31px;
        border: 1px solid #7F6AC3;
        border-radius: 4px;
        font-size: 18px;
        font-family: Aileron;
        font-weight: 400;
        line-height: 31px;
        color: #7F6AC3;
        text-align: center;
    }

    .modulqr {
        width: 710rpx;
        height: 520px;
        background: #FFFFFF;
        border-radius: 10px;
        margin: 17px auto 0;
    }

    .modulqr .tbj {
        display: flex;
        justify-content: center;
    }

    .modulqr .qrcode {
        width: 186px;
        height: 186px;
        background: #EBEBEB;
        border-radius: 14px;
        margin: 30px 0 20px 0;
    }

    .modulqr .keepqr {
        font-size: 14px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        color: #FFFFFF;
        width: 88px;
        height: 30px;
        line-height: 30px;
        text-align: center;
        background: #7F6AC3;
        border-radius: 6px;
    }

    .modulqr .chongqr {
        font-size: 14px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 24px;
        color: #ADB0BB;
        margin: 20px 0 15px;
    }

    .modulqr .qradds {
        font-size: 16px;
        font-family: Source Han Sans CN;
        font-weight: 500;
        line-height: 27px;
        color: #333333;
        margin: 0 0 20px;
    }

    .modulqr .dgpqr {
        font-size: 12px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 25px;
        color: #838AA4;
        width: 68px;
        height: 25px;
        text-align: center;
        background: #F1F2F6;
        border-radius: 6px;
    }

    .modulqr .linehang {
        width: 335px;
        height: 1px;
        background: #EBEBEB;
        margin: 30px 0 20px 0;
    }

    .modulqr .tottl {
        font-size: 12px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 20px;
        color: #838AA4;
        margin: 0 10px;
    }
</style>
